<template>
  <div>
    <c-header :p-title="'发送新消息'">
      <div class="d-flex justify-content-end align-items-center">
        <button type="button" class="btn btn-sm btn-info d-lg-block"  @click="$router.go(-1)"><i class="fa fa-mail-reply m-r-sm"></i>返回</button>
      </div>
    </c-header>
    <div class="row page-content">
      <div class="col-lg-12">
        <div class="card ">
          <div class="card-header bg-info">
            <h4 class="m-b-0 text-white">新消息表单</h4>
          </div>
          <div class="card-body">
            <div class="form-body">
              <Form ref="formVal" :model="info" action="javascript:void(0)">
                <div class="row">
                  <div class="col-md-12">
                    <FormItem>
                      <div class="row">
                        <label slot='label' class="control-label text-right col-md-3">消息标题</label>
                        <div class="col-md-9">
                          <Input v-model="info.title" placeholder="请输入消息标题"/>
                        </div>
                      </div>
                    </FormItem>
                    <FormItem>
                      <div class="row">
                        <label slot='label' class="control-label text-right col-md-3">消息内容</label>
                        <div class="col-md-9">
                          <CInput v-model="info.content" type="textarea" :maxlength='400' :limit='true' :rows="5" placeholder="请输入消息内容（限 400字）"></CInput>
                        </div>
                      </div>
                    </FormItem>
                  </div>
                </div>
                <hr>
                <div class="form-actions">
                  <div class="row">
                    <div class="col-md-6">
                      <div class="row">
                        <div class="col-md-offset-3 col-md-9">
                          <btn-submit type="submit" class="btn btn-success" :p-click='formSubmitChange' >提交</btn-submit>
                          <button type="reset" class="btn btn-inverse" @click="formResetChange">重置</button>
                        </div>
                      </div>
                    </div>
                    <div class="col-md-6"> </div>
                  </div>
                </div>
              </Form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
    import serMessage from '../../serves/api-message'
    const defaultData = {
        title:"", //标题
        content:"", //内容
    };
    export default{
        props:{
            pParams:Object
        },
        data(){
            return{
                info: {},
            }
        },
        computed:{

        },
        beforeMount(){
            this.init();
        },
        methods:{
            init(){
                this.$set(this, 'info',Object.assign({},defaultData));
            },
            formResetChange(){
                this.init();
            },
            async formSubmitChange(){
                const res = await serMessage.add({
                    title:this.info.title,
                    content:this.info.content,
                });
                if(res.code==1){
                    this.$Message.success(res.message);
                    this.init();
                    this.$router.push({name:'messageDetail',params:{id:res.data}})
                }else{
                    this.$Message.error(res.message);
                }
            },
        },
        components:{
        }
    }
</script>